package com.infore.siteManagement.PlatformInvocationServices.Service.Impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.infore.siteManagement.PlatformInvocationServices.Service.RemoteControlAndStationManageService;
import com.infore.siteManagement.PlatformInvocationServices.remoteService.IRemoteControlService;
import com.infore.siteManagement.entity.Equipment;
import com.infore.siteManagement.entity.Station;
import com.infore.siteManagement.entity.otherEntity.Instructions;
import com.infore.siteManagement.entity.otherEntity.Protocol;
import com.infore.siteManagement.repository.IEquipmentRepository;
import com.infore.siteManagement.repository.IStationRepository;
import com.infore.siteManagement.util.ResultEntity;

/**
 * 远程调用接口实现类
 * @author 刘乐法
 *
 *
 */
@Service
public class RemoteControlAndStationManageServiceImpl implements RemoteControlAndStationManageService{

	@Autowired
	private IRemoteControlService iRemoteControlService;
	@Autowired
	private IStationRepository iStationRepository;
	@Autowired
	private IEquipmentRepository iEquipmentRepository;
	
	@Override
	public ResultEntity findProtocols(String stationId) {
		// TODO Auto-generated method stub
		//站点中维护了中间表Set<ProtocolId> protocols
		Station station = iStationRepository.findOneByStationId(stationId);
		//ProtocolId维护了协议id
		Set<Protocol> protocols = station.getProtocols();
		List<String> protocolsList = new ArrayList<String>();
		for (Protocol protocol : protocols) {
			protocolsList.add(protocol.getProtocolId());
		}
		return iRemoteControlService.protocolsInfo(protocolsList);
	}

	@Override
	public ResultEntity findInstructions(String equipmentId) {
		// TODO Auto-generated method stub
		//设备维护了中间表Set<InstructionsId>
		Equipment equipment = iEquipmentRepository.findOneByEquipmentId(equipmentId);
		//中间表中得到指令id
		Set<Instructions> instructions = equipment.getInstructions();
		List<String> instructionsIdsList = new ArrayList<String>();
		for (Instructions string : instructions) {
			instructionsIdsList.add(string.getInstructionsId());
		}
		return iRemoteControlService.getInstructions(instructionsIdsList);
	}

}

